package com.example.myapplication.tack_29.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.myapplication.R;
import com.example.myapplication.tack_29.DetailActivity;
import com.example.myapplication.tack_29.data.PostData;
import com.example.myapplication.utils.Common;

import java.util.List;

public class ArrangeAdapter extends RecyclerView.Adapter<ArrangeAdapter.My> {
    private List<PostData.RowsDTO> list;
    private Context context;
    private View view;
    public ArrangeAdapter(List<PostData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_29_arrange,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        holder.name.setText(list.get(position).getName());
        holder.address.setText(list.get(position).getAddress());
        holder.salary.setText("薪资:"+String.valueOf(list.get(position).getSalary()+"/月"));
        holder.need.setText(list.get(position).getNeed());
        holder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DetailActivity.class);
                intent.putExtra(Common.COMMON,String.valueOf(list.get(position).getCompanyId()));
                context.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private TextView name;
        private TextView address;
        private TextView salary;
        private TextView need;
        private LinearLayout line;
        public My(@NonNull View itemView) {
            super(itemView);
            name = view.findViewById(R.id.name);
            address = view.findViewById(R.id.address);
            salary = view.findViewById(R.id.salary);
            need = view.findViewById(R.id.need);
            line = view.findViewById(R.id.line);
        }
    }
}
